public class AddTwoNumbers {
    //两个链表表示两个整数的各个位数的逆序，求两数相加的结果
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode head = new ListNode(0);
        ListNode cur = head;
        int bit = 0;//进制位
        while(l1!=null||l2!=null||bit!=0){
            if(l1!=null){
                bit +=l1.val;
                l1 = l1.next;
            }
            if(l2!=null){
                bit +=l2.val;
                l2 = l2.next;
            }
            cur.next = new ListNode(bit%10);
            cur = cur.next;
            bit /= 10;
        }
        return head.next;
    }
}
